package com.team.ai.service;

import com.team.ai.entity.Book;
import com.team.ai.entity.ResultEntity;
import com.team.ai.mapper.BookMapper;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class BookService {
    private static final Logger logger= LoggerFactory.getLogger(BookService.class);//日志getLogger需要传入的类名
    @Resource
    BookMapper bookMapper;
    public String insert(String title,String text,String img){
        try{
            return ResultEntity.success(bookMapper.insert(title, text,img)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String delete(int id){
        try{
            return ResultEntity.success(bookMapper.delete(id)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String update(String title,String text,String img,int id){
        try{
            return ResultEntity.success(bookMapper.update(title, text,img, id)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String selectList(){
        try{
            return ResultEntity.success(bookMapper.selectList()) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public Book selectDetail(int id){
//        try{
//            return ResultEntity.success(bookMapper.selectDetail(id)) ;
//        }catch (Exception e){
//            e.printStackTrace();
//            logger.error(e.getLocalizedMessage());
            return bookMapper.selectDetail(id);

    }

}
